﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindowsFormsApplication2
{
    class Game
    {

        private readonly static int SIDE = 20;
        public SnakePart head;
        private int score;
        private int speed;
        private int level;
        private int snakesize;
        private LinkedList<SnakePart> snake;
        private Apple apple;
        private bool command;
        private bool gameover;

        
        

        public Game()
        {
            
            this.head = new SnakePart();
            this.score = 0;
            this.speed = 300;
            this.level = 0;
            this.snake = new LinkedList<SnakePart>();
            
            this.command = true;
            this.snakesize = 3;
            this.gameover = false;
            

            Random random = new Random();
            int startdirection = random.Next(0, 4);


            if (startdirection == 0)
            {
                //Beginning snake
                snake.AddFirst(new SnakePart(13, 12, 0, 0));
                //snake.AddLast(new SnakePart(13,12,0,0)); //head
                snake.AddLast(new SnakePart(13, 13, 1, 0)); //1 piece of body
                snake.AddLast(new SnakePart(13, 14, 2, 0)); //tail
            }
            if (startdirection == 1)
            {
                //Beginning snake
                snake.AddFirst(new SnakePart(13, 12, 0, 1));
                //snake.AddLast(new SnakePart(13,12,0,0)); //head
                snake.AddLast(new SnakePart(12, 12, 1, 0)); //1 piece of body
                snake.AddLast(new SnakePart(11, 12, 2, 0)); //tail
            }
            if (startdirection == 2)
            {
                //Beginning snake
                snake.AddFirst(new SnakePart(13, 12, 0, 2));
                //snake.AddLast(new SnakePart(13,12,0,0)); //head
                snake.AddLast(new SnakePart(13, 11, 1, 0)); //1 piece of body
                snake.AddLast(new SnakePart(13, 10, 2, 0)); //tail
            }
            if (startdirection == 3)
            {
                //Beginning snake
                snake.AddFirst(new SnakePart(13, 12, 0, 3));
                //snake.AddLast(new SnakePart(13,12,0,0)); //head
                snake.AddLast(new SnakePart(14, 12, 1, 0)); //1 piece of body
                snake.AddLast(new SnakePart(15, 12, 2, 0)); //tail
            }

            this.apple = new Apple(this.snake);

        }

        public LinkedList<SnakePart> getSnake()
        {
            return this.snake;
        }

        public bool getCommand()
        {
            return this.command;
        }
        public void setCommand(bool command)
        {
            this.command = command;
        }

        public bool getGameover()
        {
            return this.gameover;
        }
        public void setGameover(bool gameover)
        {
            this.gameover = gameover;
        }

        public int getSnakesize()
        {
            return this.snakesize;
        }
        public void setSnakesize(int snakesize)
        {
            this.snakesize = snakesize;
        }


        // Setters and getters for Score
        public int getScore()
        {
            return this.score;
        }
        public void setScore(int score)
        {
            this.score = score;
        }
        public void incScore() // increment the score
        {
            this.score++;
        }

        // Setters and getters for Speed
        public int getSpeed()
        {
            return this.speed;
        }
        public void setSpeed(int speed)
        {
            this.speed = speed;
        }
        public void incSpeed() // increment the speed
        {
            this.speed=-20;
        }

        // Setters and getters for Level
        public int getLevel()
        {
            return this.level;
        }
        public void setLevel(int level)
        {
            this.level = level;
        }
        public void incLevel() // increment the level
        {
            this.level = -20;
        }

        public Apple getApple()
        {
            return this.apple;
        }
        
   
    }
}
